<template>
	<!-- <view class="content" :style="imageURL==''?'':{ backgroundImage: 'url(' + imageURL + ')' }"> -->
	<view class="content" :style="{
		backgroundColor:imageURL.Content.backgroundColor,
		backgroundImage:imageURL.Content.backgroundImage?'url('+Domain_IMG + imageURL.Content.backgroundImage+')':'',
		backgroundSize:imageURL.Content.backgroundSize,
		backgroundRepeat:imageURL.Content.backgroundRepeat,
	}">
		<view id="fixed" :style="{backgroundColor:imageURL.TopTabs.backgroundColor}" class="fixed-top"
			style="height: 220rpx; padding-top: 10px;">
			<view class="px-2 mt-7 flex" style="height: 53rpx; position: relative;">
				<!-- <image v-if="imageURL.Content.Logo" style="height: 100%; position:absolute; left: 20rpx;" :src="Domain_ICON + '/ShiJiHuaLianLoGo.jpg'" mode="heightFix"></image> -->
				<view class="font" @click="getMapLocation">
					<image :src="Domain_ICON + '/address.png'" mode="" style="width: 25rpx; height: 25rpx;"></image>
					{{address}}
				</view>
				<!--  -->
				<!-- 切换商户页面 -->
				<!-- <view v-if="isDealer" class="flex justify-between" style="margin: auto; width: 20%;">
					<view class="border-bottom border-info">
						<text class="font font-weight-bold text-info">客户</text>
					</view>
					<view>
						<text class="font font-weight-bold" @click="user()">商户</text>
					</view>
				</view> -->
			</view>
			<!-- #ifdef MP -->
			<view class="flex align-center mt-1" style="height: 80rpx;">
				<!-- 搜索框 -->
				<view class="ml-2 flex align-center justify-between flex-1 rounded-circle px-1"
					style="background-color: #F6F7F8;color: #959FA0; height: 30px;" @click="GoSearch()">
					<text class="font pl-2">搜索您想要的商品</text>
					<image :src="Domain_ICON + '/search.png'" mode=""
						style="margin-right: 8px; width: 40rpx; height: 40rpx;"></image>
				</view>
				<view class="flex align-center p-1 mx-2"
					style="background-color: #F6F7F8;color:#959FA0;border-radius: 50%;" @click="orderify()">
					<image style="width: 32rpx; height: 32rpx;" :src="Domain_ICON + '/orders.png'" mode="widthFix">
					</image>
				</view>
			</view>
			<!-- #endif -->
		</view>
		<!-- 轮播图 -->
		<view class="" :style="'height:'+fixedHeight+'px'"></view>
		<view class="mx-1 pt-2">
			<swiperDot v-show="swipers.length>0?true:false" class="position-relative" :current="current"
				:info="swipers">
				<swiper :autoplay="true" :interval="3000" :duration="500" circular style="height: 500rpx;"
					@change="changeIndicatorDots">
					<swiper-item @click="handleSwiper(item)" v-for="(item,index) in swipers" :key="index">
						<image :src="Domain_IMG + item.Picture_URL" mode="widthFix" class="rounded"
							style="width: 100%;"></image>
					</swiper-item>
				</swiper>
			</swiperDot>
		</view>
		<!-- icon搜索 -->
		<view class="flex justify-center mx-1 rounded my-2" :style="{backgroundColor:imageURL.Icon.backgroundColor}">
			<view class="pb-2 my-1 flex flex-wrap" style="width: 700rpx;">
				<view @click="handleSkip(item.url,item.ShopColumn_Id)"
					class="flex flex-column align-center justify-center mt-2 rounded-lg"
					:class="(index+1)%4!=0?'mr-2':''" style="width: 160rpx; height: 160rpx;"
					:style="{backgroundColor:imageURL.Icon.IconBackgroundColor}" v-for="(item,index) in myItemsArr"
					:key="item.ShopColumn_Id">
					<image style="height: 100rpx;width: 100rpx;" :src="Domain_IMG + item.src" mode="heightFix"></image>
					<text class="font-sm" :style="{Color:imageURL.Icon.textColor}">{{item.name}}</text>
				</view>
			</view>
		</view>
		<!-- 本周推荐 -->
		<view class="pl-3 pb-2" v-if="weeklyRecommend.length > 0">
			<text class="h3 text-success font-weight-bold">本周推荐</text>
			<view class="flex" style="overflow-x: scroll;">
				<view class="rounded-lg bg-light mr-2" style="width: 200rpx; height: 270rpx;"
					v-for="(item,index) in weeklyRecommend" :key="index">
					<image class="rounded-lg" style="width: 200rpx; height: 200rpx;" :src="Domain_IMG + item.src"
						mode=""></image>
					<view class="text-ellipsis" style="70rpx">
						<text class="font-sm">商品名称</text>
					</view>
				</view>
			</view>
		</view>
		<!-- 导航栏 -->
		<view id="tab" class="flex align-center" style="height: 65px;">
			<scroll-view :class="topfixed?'tabs-fixed':''" scroll-x="true" scroll-with-animation
				:scroll-left="scrollLeft" class="pt-2 pb-2"
				:style="{backgroundColor:tabs.length>0?imageURL.Tabs.backgroundColor:''}">
				<view class="px-3 flex justify-between align-end" :style="{width:Width()}">
					<text :id="'tab_'+index" class="h4 text-hover-dark font-weight-bold"
						:style="{Color:index==tabsIndex?imageURL.Tabs.selectColor:imageURL.Tabs.textColor}"
						:class="index == tabsIndex ? 'first' : ''" v-for="(item,index) in tabs" :key="index"
						@tap="handleTab(index)">{{item.Column_Name}}</text>
				</view>
			</scroll-view>
		</view>
		<!-- 导航栏对应商品内容 -->
		<scroll-view scroll-y="true" class="scroll-Y">
			<view :id="'item'+index" class="pb-3" v-for="(item,index) in tabs" :key="index">
				<!-- <view :id="'item'+index" :class="[index%2==0?'bg-white':'bg-light']" class=" px-3 pb-3" v-for="(item,index) in tabs" :key="index"> -->
				<view class="h4 text-hover-dark font-weight-bold pt-2 pb-2" style="margin-left: 4%;" v-if="index != 0">
					{{item.Column_Name}}
				</view>
				<view class="flex flex-wrap">
					<view class="mb-3 rounded-lg lazy-container"
						:style="{backgroundColor:imageURL.Detail.backgroundColor}"
						style="margin-left: 4%; width: 44%; height: 500rpx; position: relative;"
						v-for="(item_,index_) in item.data" :key="index_" @click="handleDetails(
				item_.Article_SerialNumber,
				item_.Sales_Unit_Price_SerialNumber,
				item_.Store_SerialNumber,
				item_.specifications[0].Sales_Unit_Price)">
						<!--<view class="mb-3 rounded-lg" :class="[index%2==0?'bg-light':'bg-white']" style="width: 320rpx; height: 500rpx; position: relative;" v-for="(item_,index_) in item.data" :key="index_"
					@click="handleDetails(item_.Article_SerialNumber,item_.Sales_Unit_Price_SerialNumber,item_.Store_SerialNumber,item_.specifications[0].Sales_Unit_Price)"> -->
						<image class="rounded-lg" style="width: 100%;
						height: 320rpx;" :src="Domain_IMG + item_.Picture_URL" mode="" :lazy-load="true"></image>
						<view class="flex flex-column ml-2 text-ellipsis" style="70rpx">
							<view class="flex text-ellipsis">
								<view class="p-1 mr-1 text-white" :style="{backgroundColor:imageURL.Detail.themeColor}"
									style="border-radius: 10rpx;font-size: 22rpx;font-family: PingFang SC;">
									世纪华联
								</view>
								<view class="text-ellipsis"
									style="text-align: left;width: 50%;font-family: PingFang SC;">
									<text class="font">{{item_.Article_Name}}</text>
								</view>
							</view>
							<text style="display: block;"
								class=" font-small text-secondary my-1">{{item_.Category_Name}}</text>
							<text style="display: block;"
								class=" font-small text-secondary">仅剩{{item_.specifications[0].Stock_Remain}}件</text>
							<text style="display: block;"
								class=" h4 font-weight-bold">￥{{item_.specifications[0].Sales_Unit_Price}}</text>
						</view>
						<!-- 购物车添加 -->
						<view v-if="!Car.some(i=>i.Article_SerialNumber==item_.Article_SerialNumber)"
							class="add flex justify-center align-center rounded-circle"
							:style="{backgroundColor:imageURL.Detail.themeColor}"
							@click.stop="addShopCar(item_.Store_SerialNumber,item_.specifications[0].Sales_Unit_Price,item_.specifications[0].Sales_Unit_Price_Stock_SerialNumber,item_.Article_SerialNumber,item_.specifications[0].Article_Specifications_SerialNumber,item_.specifications[0].Unit_Price,item_.specifications[0].Sign)">
							<uni-icons type="plusempty" color="white" size="20"></uni-icons>
						</view>
						<!-- 购物车修改 -->
						<view v-else class="flex justify-center align-center rounded-circle"
							style="position: absolute; right: 20rpx;bottom: 20rpx;">
							<view @click.stop="subGoods(item_.Article_SerialNumber)"
								class="font-md text-center text-white flex justify-center align-center"
								:style="{backgroundColor:imageURL.Detail.themeColor}"
								style="width: 50rpx;height: 50rpx;">-</view>
							<view class="text-center font bg-white border " style="width: 50rpx;height: 50rpx;"
								:style="'border-top:1rpx solid '+imageURL.Detail.themeColor+';border-bottom:1rpx solid '+imageURL.Detail.themeColor+'; color:'+imageURL.Detail.themeColor+'; box-sizing: border-box;'">
								{{parseInt(Car.filter(i=>i.Article_SerialNumber==item_.Article_SerialNumber)[0].Quantity)}}
							</view>
							<view @click.stop="addGoods(item_.Article_SerialNumber)"
								class="font-md text-center text-white flex justify-center align-center"
								:style="{backgroundColor:imageURL.Detail.themeColor}"
								style="width: 50rpx;height: 50rpx;">+</view>
						</view>
					</view>
				</view>
			</view>
		</scroll-view>
		<!-- 悬浮按钮 -->
		<view class="button flex flex-column-reverse">
			<view class="shadow mt-2 bg-white rounded-circle flex justify-center align-center"
				style="width: 100rpx; height: 100rpx; position: relative;" @click="handleBtn(item.title)"
				v-if="item.isShow" v-for="(item,index) in btn" :key="index">
				<i v-if="item.title=='car'&&total>0" class="bg-danger rounded-circle text-white px-1 font-sm"
					style="position: absolute; top: -5rpx;left: -5rpx;">{{total}}</i>
				<image :src="Domain_ICON + item.icon" style="width: 50rpx; height: 50rpx;" mode=""></image>
				<button id="shareBtn" class="rounded-circle" open-type="share" v-if="item.title=='share'">分享</button>
			</view>
		</view>
		<!-- 底部切换 -->
		<tabsBottom :tabId="0"></tabsBottom>
	</view>
	</view>
</template>

<script>
	const app = getApp();
	import times from "@/mixins/time.js";
	import swiperDot from "@/components/comon/swiper-doc.vue";
	import tabsBottom from "@/components/tabs/tabs-bottom.vue";
	import {
		WXShopCarQuantity
	} from "@/api/WeChat.js";
	import {
			WXAppStyle,getWeChatAddressHLAction
	} from "@/api/global.js";
	import {
		WX2ColumnAction,
		WX2GoodsAllAction,
		WXCarouselChartAction,
		WXEditShopCarQuantity,
	} from "@/api/article.js";
	import QQMapWX from "common/qqmap-wx-jssdk.min.js";
	export default {
		components: {
			swiperDot, //轮播图组件
			tabsBottom,
		},
		data() {
			return {
				isDealer: false,
				OpenID: "",
				ShareOpenID: "",
				Enterprise_Info_SerialNumber: "",
				App_ID: "",
				Car: [],
				TopColor: false,
				imageURL: {
					// Content:{//总背景
					// 	backgroundColor:'#dc3545',
					// 	backgroundImage:'',//背景图片'/6c1e39e6b6bc4258537d8b6691d41e4.png'
					// 	backgroundSize:'100% auto',//尺寸
					// 	backgroundRepeat:'no-repeat',//是否重复渲染
					// 	Logo:false,//logo展示
					// },
					// TopTabs:{
					// 	backgroundColor:'',
					// },
					// Icon:{//图标
					// 	backgroundColor:'',
					// 	IconBackgroundColor:'#fff',
					// 	textColor:'#000',
					// },
					// Tabs:{//导航栏
					// 	backgroundColor:'rgba(0, 0, 0, 0.5)',
					// 	textColor:'#a3ff0e',
					// 	selectColor:'#dcdc08',
					// 	//区域
					// },
					// Detail:{//商品卡片
					// 	backgroundColor:'#fff',//背景颜色
					// 	themeColor:'#dcdc08',//主体颜色
					// },
				},
				Dealer_Authority: "", //认证身份绑定的账号
				Domain_IMG: app.globalData.Domain_IMG, //全局变量域名
				Domain_ICON: app.globalData.Domain_ICON, //全局变量域名
				current: 0, // 标识当前选中的图片序列号
				fixedHeight: 0, //顶部高度
				tabsIndex: 0, // 导航栏被选中栏目的索引，默认0
				topfixed: false, //控制悬停导航栏是否显示
				isClick: false, //为了解决点击滑动的bug，点击的时候，滑动里面不处理任何逻辑
				loading: false, //节流
				tabsHeight: 0, //导航栏高度
				scroll_top: 0, //滚动的距离
				total: 0, //数量
				times: "",
				scrollLeft: 0, //导航栏横向滚动距离
				scrollViewWidth: 0, //初始化滚动的宽度
				itemsHeight: [], //导航栏选项内容到顶部距离-目标节点的数组
				swipers: [], //轮播图
				tabs: [], //选项卡数据
				myItemsArr: [], //主类目数据
				weeklyRecommend: [],
				btn: [{
						//右侧悬浮按钮
						title: "serve",
						icon: "/serve.png",
						isShow: true,
					},
					{
						title: "car",
						icon: "/shop_car.png",
						isShow: true,
					},
				],
				Picture_URL: {}, //临时路径
				address: ""
			};
		},
		onReady() {
			this.WXAppStyle({
				Enterprise_Info_SerialNumber: app.globalData.enterprise,
				App_ID: app.globalData.appid,
			});
		},
		onLoad(e) {
			if (app.globalData.enterprise != "") {
				uni.showLoading({
					title: "加载中",
				});
			}
			const openid = uni.getStorageSync("openid");
			uni.setStorageSync("ShareUrl", `/pages/index/index?openid=${openid}`);
			if (e.openid) {
				this.ShareOpenID = e.openid;
				this.OpenID = uni.getStorageSync("openid");
				this.Enterprise_Info_SerialNumber = app.globalData.enterprise;
				this.App_ID = uni.getStorageSync("App_ID");
				//不可以自己分享给自己
				if (this.ShareOpenID != this.OpenID) {
					uni.request({
						//获取点击的分享者传给服务器
						url: app.globalData.Domain_Name + "/WXMemberBehaviorAddAction",
						header: {
							"Content-Type": "application/x-www-form-urlencoded",
						},
						method: "POST",
						data: {
							Parent_Open_ID: this.ShareOpenID,
							Open_ID: this.OpenID,
							Enterprise_Info_SerialNumber: this.Enterprise_Info_SerialNumber,
							App_ID: this.App_ID,
							Meet_Type: "分享",
						},
						success: (res) => {},
					});
				}
			}
			this.fixed(); //获取顶部导航栏高度
			this.scrollWidth(); //获取屏幕宽度
			if (app.globalData.openid != "") {
				this.getData(app.globalData.openid);
			} else {
				app.watch(this.getData, "memberInfo"); //监听openid变化
			}
			uni.hideLoading();
		},
		onShow() {
			if (app.globalData.openid != "") {
				this.ShopGoods();
			}
		},
		//页面滚动
		onPageScroll(e) {
			this.scroll_top = e.scrollTop;
			if (e.scrollTop > 10) {
				this.TopColor = true;
			} else {
				this.TopColor = false;
			}
			//导航栏是否悬空
			uni.createSelectorQuery().select("#tab").boundingClientRect((data) => {
					if (data.top <= this.fixedHeight) {
						this.topfixed = true;
					} else {
						this.topfixed = false;
					}
				})
				.exec();
			//导航栏栏目随对应模块自动切换
			if (!this.isClick) {
				this.scrollTochang(e.scrollTop);
			}

			const observer = uni.createIntersectionObserver(this, {
				thresholds: [0],
			});

			observer.relativeToViewport().observe(".target-element", (res) => {
				if (res.intersectionRatio > 0) {
					console.log("Element is in the viewport");
					// 可以通过 res.boundingClientRect 来获取元素的位置信息，例如：res.boundingClientRect.top, res.boundingClientRect.left 等
				}
			});
		},
		// watch:{
		// 	Dealer_Authority:function(){
		// 		this.isDealer = true
		// 	}
		// },
		methods: {
			//地图
			getMapLocation() {
				uni.chooseLocation({
					success: (res) => {
						let reg = /.+?(省|市|自治区|自治州|县|区)/g
						this.getLocationInfo(res.longitude, res.latitude)
					},
					fail: () => {
						// 如果用uni.chooseLocation没有获取到地理位置，则需要获取当前的授权信息，判断是否有地理授权信息
						uni.getSetting({
							success: (res) => {
								console.log(res);
								var status = res.authSetting;
								if (!status['scope.userLocation']) {
									// 如果授权信息中没有地理位置的授权，则需要弹窗提示用户需要授权地理信息
									uni.showModal({
										title: "是否授权当前位置",
										content: "需要获取您的地理位置，请确认授权，否则地图功能将无法使用",
										success: (tip) => {
											if (tip.confirm) {
												// 如果用户同意授权地理信息，则打开授权设置页面，判断用户的操作
												uni.openSetting({
													success: (data) => {
														// 如果用户授权了地理信息在，则提示授权成功
														if (data
															.authSetting[
																'scope.userLocation'
															] === true
														) {
															uni.showToast({
																title: "授权成功",
																icon: "success",
																duration: 1000
															})
															// 授权成功后，然后再次chooseLocation获取信息
															uni.chooseLocation({
																success: (
																	res
																) => {
																	console
																		.log(
																			"详细地址",
																			res
																		);
																}
															})
														} else {
															uni.showToast({
																title: "授权失败",
																icon: "none",
																duration: 1000
															})
														}
													}
												})
											}
										}
									})
								}
							},
							fail: (res) => {
								uni.showToast({
									title: "调用授权窗口失败",
									icon: "none",
									duration: 1000
								})
							}
						})
					}
				});
			},
			//异地址解析
			getLocationInfo(longitude, latitude) {
				const _this = this;
				return new Promise((resolve) => {
					//位置信息默认数据
					let location = {
						longitude,
						latitude,
						province: "",
						city: "",
						area: "",
						street: "",
						address: "",
					};
					const qqmapsdk = new QQMapWX({
						key: "IH2BZ-LHWC5-FJDI3-I6ITE-SUKD3-NMF4B", //这里填写自己申请的key
					});
					qqmapsdk.reverseGeocoder({
						location,
						success(response) {
							let info = response.result;
							location.province = info.address_component.province;
							location.city = info.address_component.city;
							location.area = info.address_component.district;
							location.street = info.address_component.street;
							location.address = info.address;
							location.name = info.address_reference.landmark_l2.title,
							location.town = info.address_reference.town.title
							let time = parseInt(new Date().getTime() / 1000) + 1800;
							uni.setStorageSync("location", {
								data: location,
								expires_in: time,
							});
							// _this.getWeChatAddressHL();
							_this.address = uni.getStorageSync("location").data.name;
						},
					});
				});
			},
			async getWeChatAddressHL() {
				const res = await getWeChatAddressHLAction({
					Address: uni.getStorageSync("location").data.town
				});
				if (res.enterprise_info.length == 0) {
					uni.showToast({
						title: '您当前地区无店铺',
						icon: "none",
						duration: 2000 // 持续时间，单位毫秒
					});
				} else if (res.enterprise_info[0].Enterprise_Info_SerialNumber == app.globalData.enterprise) {
				
				} else {
					app.globalData.enterprise = res.enterprise_info[0].Enterprise_Info_SerialNumber;
					//刷新页面
					uni.reLaunch({
						url: "/pages/index/index",
					})
				}
			},
			user(url) {
				//商户跳转方法
				uni.showModal({
					title: "提示",
					content: "您将进入供应商页面,是否继续",
					success: function(res) {
						//5_2跳转到个人信息详情页
						if (res.confirm) {
							//跳转到页面
							uni.navigateTo({
								url: "/pages/Merchant/index",
							});
						}
					},
				});
			},
			async subGoods(Article_SerialNumber) {
				if (this.loading) return;
				uni.showLoading({
					title: "提交中...",
				});
				this.loading = true;
				const res = await WXEditShopCarQuantity({
					Article_SerialNumber,
					Open_ID: app.globalData.openid,
					Type: 0,
				});
				this.loading = false;
				if (res.Status == "success") {
					const res1 = await WXShopCarQuantity({
						App_ID: app.globalData.appid,
						Open_ID: app.globalData.openid,
						Enterprise_Info_SerialNumber: app.globalData.enterprise,
					});
					if (res1.Status == "success") {
						this.total = 0;
						res1.Data.forEach((item) => {
							this.total = this.total + parseInt(item.Quantity);
						});
						this.Car = res1.Data;
						uni.hideLoading();
					}
				}
			},
			async addGoods(Article_SerialNumber) {
				if (this.loading) return;
				uni.showLoading({
					title: "提交中...",
				});
				this.loading = true;
				const res = await WXEditShopCarQuantity({
					Article_SerialNumber,
					Open_ID: app.globalData.openid,
					Type: 1,
				});
				this.loading = false;
				if (res.Status == "success") {
					const res1 = await WXShopCarQuantity({
						App_ID: app.globalData.appid,
						Open_ID: app.globalData.openid,
						Enterprise_Info_SerialNumber: app.globalData.enterprise,
					});
					if (res1.Status == "success") {
						this.total = 0;
						res1.Data.forEach((item) => {
							this.total = this.total + parseInt(item.Quantity);
						});
						this.Car = res1.Data;
						uni.hideLoading();
					}
				}
			},
			async ShopGoods() {
				const res = await WXShopCarQuantity({
					App_ID: app.globalData.appid,
					Open_ID: app.globalData.openid,
					Enterprise_Info_SerialNumber: app.globalData.enterprise,
				});
				if (res.Status == "success") {
					this.total = 0;
					res.Data.forEach((item) => {
						this.total = this.total + parseInt(item.Quantity);
					});
					this.Car = res.Data;
				}
			},
			Width() {
				//自适应导航栏外层长度
				return this.tabs.length * 180 + "rpx";
			},
			async WXAppStyle(data) {
				const res = await WXAppStyle(data);
				if (res.Status == "success" && res.Data) {
					console.log(res.Data.index);
					this.imageURL = res.Data.index;
				}
			},
			//点击轮播图
			handleSwiper(item) {
				if (item.Carousel_Chart_Type == "0") {
					handleDetails(
						item.Article_SerialNumber,
						item.Sales_Unit_Price_SerialNumber,
						item.Store_SerialNumber
					);
				} else if (item.Carousel_Chart_Type == "1") {
					uni.navigateTo({
						url: item.Carousel_Chart_Path,
					});
				}
			},
			scrollWidth() {
				//初始化求出tab滚动宽度
				this.createSelectorQuery()
					.select("#tab")
					.boundingClientRect((rect) => {
						this.scrollViewWidth = Math.round(rect.width);
					})
					.exec();
			},
			scrollHeight() {
				//tab下所有内容，其每个内容的高度
				this.$nextTick(() => {
					//渲染完成后再执行
					//导航栏是否悬空
					uni.createSelectorQuery().select("#tab").boundingClientRect((data) => {
							if (data) this.tabsHeight = data.height;
						}).exec();
					this.tabs.forEach((item, index) => {
						uni.createSelectorQuery().select(`#item${index}`).boundingClientRect((res) => {
								//(res.top + res.height)为导航栏 (44 + this.tabsHeight)为目标节点
							if (res)
								this.itemsHeight.push(res.top + res.height - (this.fixedHeight + this.tabsHeight));
						}).exec();
					});
				});
			},
			handleDetails(
				Article_SerialNumber,
				Sales_Unit_Price_SerialNumber,
				Store_SerialNumber,
				Sales_Unit_Price
			) {
				//点击进入"商品详情"页
				uni.navigateTo({
					url: "/pages/index/details?Article_SerialNumber=" +
						Article_SerialNumber +
						"&Sales_Unit_Price_SerialNumber=" +
						Sales_Unit_Price_SerialNumber +
						"&Store_SerialNumber=" +
						Store_SerialNumber +
						"&Sales_Unit_Price=" +
						Sales_Unit_Price +
						"&ShareOpenid=" +
						this.ShareOpenID,
				});
			},
			handleSkip(url, id) {
				//点击跳转"搜索结果"页
				uni.navigateTo({
					url: url + "?id=" + id,
				});
			},
			async getData(openid) {
				this.getGoods(); //查询商品信息
				const res = await WXShopCarQuantity({
					App_ID: app.globalData.appid,
					Open_ID: app.globalData.openid,
					Enterprise_Info_SerialNumber: app.globalData.enterprise,
				});
				if (res.Status == "success") {
					res.Data.forEach((item) => {
						this.total = this.total + parseInt(item.Quantity);
					});
					this.Car = res.Data;
				}
				this.address = uni.getStorageSync("location").data.name;
			},
			handleTab(index) {
				//点击导航栏后选项据中且页面滚动到对应位置
				const that = this;
				this.isClick = true;
				this.tabsIndex = index;
				//选项据中
				uni.createSelectorQuery().select("#tab_" + index).boundingClientRect((rect) => {
						this.scrollLeft =
							rect.left - this.scrollViewWidth / 2 + rect.width / 2;
					})
					.exec();
				//页面滚动
				uni.createSelectorQuery().select("#item" + index).boundingClientRect((data) => {
						let scrollTop = data.top - (this.fixedHeight + this.tabsHeight) + this.scroll_top;
						uni.pageScrollTo({
							scrollTop,
							duration: 300,
							complete: function() {
								const timer = setTimeout(() => {
									that.isClick = false; // 关闭(放开对onPageScroll的限制)
									clearTimeout(timer);
								}, 500); //解决ios和安卓、鸿蒙系统兼容性问题,但在开发者环境会出现问题
							},
						});
					})
					.exec();
			},
			scrollTochang(scrollTop) {
				//页面滚动到指定位置时切换tabs导航栏选项(点击导航栏执行时不生效)
				const index = this.itemsHeight.findIndex((item) => scrollTop < item);
				if (this.tabsIndex != index) {
					this.tabsIndex = index;
					//选项据中
					uni
						.createSelectorQuery()
						.select("#tab_" + index)
						.boundingClientRect((rect) => {
							if (rect)
								this.scrollLeft =
								rect.left - this.scrollViewWidth / 2 + rect.width / 2;
						})
						.exec();
				}
			},
			GoSearch() {
				//跳转到"搜索"页
				uni.navigateTo({
					url: "/pages/index/search",
				});
			},
			orderify() {
				//跳转到"订单"页
				uni.navigateTo({
					url: `/pages/my/order?id=0`,
				});
			},
			changeIndicatorDots(e) {
				//每次轮播修改轮播图数
				this.current = e.detail.current;
			},
			//根据数组中所有对象某个值进行排序
			Objectsort(property) {
				return function(Obj1, Obj2) {
					return Obj1[property] - Obj2[property];
				};
			},
			handleBtn(title) {
				//点击屏幕左侧悬浮按钮"客服"按钮后对应操作
				if (title == "serve") {
					//进入"客服"页
					uni.navigateTo({
						url: "../serves/serves",
					});
				} else if (title == "car") {
					//进入"购物车"页
					uni.redirectTo({
						url: "../shopcar/shopcar",
					});
				}
			},
			time() {
				this.times = times.nowtime();
			},
			fixed() {
				//顶部模块高度获取
				const query = uni.createSelectorQuery();
				query
					.select("#fixed")
					.boundingClientRect((data) => {
						this.fixedHeight = data.height;
					})
					.exec();
			},
			async getGoods() {
				//类目
				this.myItemsArr = await WX2ColumnAction({
					Enterprise_Info_SerialNumber: app.globalData.enterprise,
					App_ID: app.globalData.appid,
				});
				//商品
				this.tabs = await WX2GoodsAllAction({
					App_ID: app.globalData.appid,
					Enterprise_Info_SerialNumber: app.globalData.enterprise,
				});
				console.log(this.tabs);
				this.tabs.forEach((item) => {
					//根据Column_Sequence值进行排序
					if (item.Column_Sequence == "") {
						item.Column_Sequence = 1000;
					}
				});
				this.tabs.sort(this.Objectsort("Column_Sequence"));
				this.scrollHeight();
				//轮播图
				this.swipers = await WXCarouselChartAction({
					App_ID: app.globalData.appid,
					Enterprise_Info_SerialNumber: app.globalData.enterprise,
				});
			},
			addShopCar(Store_SerialNumber,Sales_Unit_Price,Sales_Unit_Price_Stock_SerialNumber,Article_SerialNumber,Article_Specifications_SerialNumber,Unit_Price,Sign) {
				//加入购物车
				this.time();
				if (!this.loading) {
					this.loading = true;
					uni.showLoading({
						title: "提交中...",
					});
					uni.request({
						header: {
							"Content-Type": "application/x-www-form-urlencoded",
						},
						url: app.globalData.Domain_Name + "/WXCheckShopCarAction", //
						method: "POST",
						data: {
							Open_ID: app.globalData.openid,
							App_ID: app.globalData.appid,
							Sales_Unit_Price_Stock_SerialNumber,
						},
						success: (res) => {
							if (res.data.length == 0) {
								uni.request({
									header: {
										"Content-Type": "application/x-www-form-urlencoded",
									},
									url: app.globalData.Domain_Name + "/getAddAction?grant_type=wechat_program", //
									method: "POST",
									data: {
										Data: JSON.stringify({
											sales_order: [{
												Sales_Order_SerialNumber: "",
												Store_SerialNumber: Store_SerialNumber,
												Sales_Date: this.times,
												Open_ID: app.globalData.openid,
												Sales_Amount: Sales_Unit_Price,
												Collection_Amount: 0,
												Sales_ID: "xiaoshou1",
												Receive_Type: 0,
												Refund_Type: 0,
												Row_Status: 8,
												App_ID: app.globalData.appid,
												Enterprise_Info_SerialNumber: app
													.globalData.enterprise,
												Children: {
													sales_order_detail: [{
														Sales_Order_Detail_SerialNumber: "",
														Sales_Order_SerialNumber: "",
														Sales_Unit_Price_Stock_SerialNumber: Sales_Unit_Price_Stock_SerialNumber,
														Article_SerialNumber: Article_SerialNumber,
														Article_Specifications_SerialNumber: Article_Specifications_SerialNumber,
														Sign: Sign,
														Quantity: 1,
														Unit_Price: Unit_Price,
														Sales_Unit_Price: Sales_Unit_Price,
														Amount: Sales_Unit_Price,
														Receive_Type: 0,
														Refund_Type: 0,
														Row_Status: 8,
														Enterprise_Info_SerialNumber: app
															.globalData
															.enterprise,
													}, ],
												},
											}, ],
										}),
										Open_ID: app.globalData.openid,
									},
									success: (res) => {
										if (res.data.Status == "success") {
											uni.showToast({
												title: "已加入购物车！",
												icon: "none",
											});
											this.total++;
											this.ShopGoods();
										} else {
											uni.showToast({
												title: "系统繁忙！",
												icon: "error",
											});
										}
									},
									complete: () => {
										this.loading = false;
										uni.hideLoading();
									},
								});
							} else {
								this.loading = false;
								uni.hideLoading();
								uni.showToast({
									title: "购物车存在该商品！",
									icon: "none",
								});
							}
						},
					});
				}
			},
		},
	};
</script>

<style lang="scss">
	.tabs-fixed {
		position: fixed;
		top: 120px;
		z-index: 1030;
	}

	.first {
		font-size: 45rpx;
		line-height: 1.8;
		font-weight: 700;
	}

	.add {
		position: absolute;
		bottom: 20rpx;
		right: 20rpx;
		width: 50rpx;
		height: 50rpx;
		line-height: 50rpx;
	}

	.button {
		position: fixed;
		bottom: 200rpx;
		right: 20rpx;
		width: 100rpx;
	}
</style>